import React, { Component } from 'react'
import { Button } from 'antd-mobile'

const setInputValue = _this => ({
  username: {
    value: '',
    onChange: e => _this.setState(state => ({ username: { ...state.username, value: e.target.value } }))
  },
  password: {
    value: '',
    onChange: e => _this.setState(state => ({ password: { ...state.password, value: e.target.value } }))
  }
})

class Login extends Component {
  state = {
    ...setInputValue(this)
  }

  render() {
    let { username, password } = this.state
    return (
      <div>
        <div>
          <label>
            账号：
            <input type="text" {...username} />
          </label>
        </div>
        <div>
          <label>
            密码：
            <input type="text" {...password} />
          </label>
        </div>
        <div>
          <Button
            type="primary"
            onClick={() => {
              console.log(this.state)
            }}
          >
            用户登录
          </Button>
        </div>
      </div>
    )
  }
}

export default Login
